*Recoding ZA5321 

use "Data\ZA5321\ZA5321_v2-1-0.dta" , clear

*Support for democracy
gen $idea_democracy				= d86	//2005

*Satisfaction with democracy
gen $satisfaction_democracy		= d40

*Efficacy
gen $politicians_takecare = d170a
gen $ego_politicdiscuss = d170i
gen $ego_politicscomplicated = d170d


*define missing values
mvdecode $idea_democracy $satisfaction_democracy $politicians_takecare $ego_politicdiscuss $ego_politicscomplicated, mv(99=.a\98=.b)  //.a = no answer; .b = don't know

*standardize scale
replace $idea_democracy = ($idea_democracy-1)/5 if !missing($idea_democracy)	 
replace $satisfaction_democracy = ($satisfaction_democracy-1)/5 if !missing($satisfaction_democracy)

foreach var of varlist  $ego_politicdiscuss {
	replace `var' = (`var' )/6 if !missing(`var')
}

foreach var of varlist $ego_politicscomplicated $politicians_takecare {
	replace `var' = (6 - `var')/6 if !missing(`var')
}



*Support for liberal democracy
	*not asked

*Sociodemographic Controls
gen			$gender 			= sex-1

gen		 	$age				= jahr							  	//survey year - year of birth	
*define missing values
mvdecode $age, mv(9999=.a)  //.a = no answer
replace $age					= 2005-$age if !missing($age)

gen 		$education			= dbildga
*define missing values
mvdecode	$education, mv(99=.a\98=.b)  //.a = no answer; .b = don't know
replace 	$education 			= 0 if $education 	<= 4 & !missing($education) // Still in School, none, Hautpschule, Mittlere Reife, = 0
replace 	$education 			= 1 if $education 	>=5  & !missing($education) // Abitur/EOS; university = 1

gen 		$eastwest 				= dsplitwo

*Party ID
*Did R lean towards  a left, right or other party?
*1: right, (CDU/CSU, FDP, AfD), 0: left (Left/PDS, Greens, SPD), -1: other
gen $partyid_category		= 1 	if inlist(dpid_a, 1, 2, 5)
replace $partyid_category	= 0 	if inlist(dpid_a, 4, 6, 7)
replace $partyid_category	= -1 	if inlist(dpid_a, 801)


*Party Vote
*Did R lean towards  a left, right or other party?
*1: right, (CDU/CSU, FDP, AfD), 0: left (Left/PDS, Greens, SPD), -1: other
gen $partyvote_category		= 1 	if inlist(d64a, 1, 5)
replace $partyvote_category	= 0 	if inlist(d64a, 4, 6, 7)
replace $partyvote_category	= -1 	if inlist(d64a, 801)




*Meta variables
gen 		$dataset 					= "ZA5321"
gen 		$year 						= 2005

*Weight
gen weight = wei_ipf

*Check
tab $idea_democracy d86, m
tab $satisfaction_democracy d40, m
tab $gender sex, m
tab $age, m
tab $education dbildga, m
tab $eastwest dsplitwo, m


*Save recode dataset
keep $idea_democracy $satisfaction_democracy $politicians_takecare $ego_politicdiscuss $ego_politicscomplicated $gender $age $education $eastwest $dataset $year weight	$partyid_category	$partyvote_category	
save ZA5321_recoded.dta, replace
